import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.LinkedBlockingQueue;

public class SingleMain {
	
	public static final int MAX_PAGES = 200;

	public static void main(String[] args) {
		ArrayList<String> keys = new ArrayList<String>();
		LinkedBlockingQueue<String> urlQueue = new LinkedBlockingQueue<String>();
		LinkedBlockingQueue<WebPage> webPageQueue = new LinkedBlockingQueue<WebPage>();
		ConcurrentSkipListSet<String> pagesVisited = new ConcurrentSkipListSet<String>();
		ConcurrentSkipListSet<String> disallowList = new ConcurrentSkipListSet<String>();
		
		Scanner input = new Scanner(System.in);
		System.out.println("Welcome to The Cardboard Boxes WebCrawler!\n");
		
		System.out
				.println("\nPlease enter up to 10 keywords that you would like to search for...");
		System.out.println("(Enter '~' if you are done entering words)");
		

		String temp;
		for (int i = 0; i < 10; i++) {
			System.out.print(i + 1 + ") ");
			if (input.hasNext()) {
				temp = input.next();
				if (!temp.equalsIgnoreCase("~"))
					keys.add(temp);
				else
					break;
			}
		}

		System.out.println("\nSearching for keywords: " + keys.toString());
		System.out.println("Please enter a seed URL address (i.e. google.com): ");
		String seedURL = input.next();
		
		urlQueue.add(seedURL);
		System.out.println(urlQueue.toString());

		ActualReporter reporter = new ActualReporter(keys, MAX_PAGES);

		DataGatherer dataG = new DataGatherer(reporter);
		
		while (dataG.getTotalPages() <= MAX_PAGES) {
			pageRetriever pr = new pageRetriever(webPageQueue, urlQueue, disallowList);
			httpParser parser = new httpParser(webPageQueue, urlQueue, dataG, keys, pagesVisited, disallowList);
			pr.run();
			parser.run();
			
		}
		
	}
}
